package com.wanmait.schedule.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.wanmait.schedule.entity.Course;
import com.wanmait.schedule.entity.CourseTeacher;
import com.wanmait.schedule.entity.Teacher;
import com.wanmait.schedule.mapper.CourseTeacherMapper;
import com.wanmait.schedule.service.CourseService;
import com.wanmait.schedule.service.CourseTeacherService;
import com.wanmait.schedule.service.TeacherService;
import com.wanmait.schedule.util.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 教师课程对应关系表 前端控制器
 * </p>
 *
 * @author wanmait
 * @since 2022-12-05
 */
@RestController
@RequestMapping("/manage/courseTeacher")
@RequiresPermissions("manage:course")
public class CourseTeacherController {

    @Resource
    private TeacherService teacherService;
    @Resource
    private CourseService courseService;
    @Resource
    private CourseTeacherService courseTeacherService;

    //根据教师显示教师与课程对应列表
    @GetMapping("list")
    public AjaxResult list() {
        List<Teacher> teachers = courseTeacherService.listCourseByTeacher();
        return AjaxResult.success(teachers);
    }
    //列表分页，条件搜索
    @PostMapping("list")
    public AjaxResult list(@RequestBody CourseTeacher courseTeacher,Integer pageNum){
        PageInfo<Teacher> pageInfo = courseTeacherService.list(courseTeacher,pageNum);
        return AjaxResult.success(pageInfo);
    }

    //根据教师id查找该教师所对应的课程
    @GetMapping("listByTeacherId")
    public AjaxResult listByTeacherId(Integer id){
        List<Course> courses = courseTeacherService.listByTeacherId(id);
        return AjaxResult.success(courses);
    }

    //根据教师Id和课程ID数组，修改教师所教学课程
    @PostMapping("update")
    public AjaxResult update(Integer id,@RequestBody Integer[] ids){
        System.out.println(Arrays.toString(ids));
        courseTeacherService.update(id,ids);
        return AjaxResult.success();
    }

}
